package com.example.stuwork.controller;

import com.example.stuwork.common.Result;
import com.example.stuwork.pojo.CourseAnnouncement;
import com.example.stuwork.service.CourseAnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程公告控制器
 */
@RestController
@RequestMapping("/course-announcement")
public class CourseAnnouncementController {

    @Autowired
    private CourseAnnouncementService courseAnnouncementService;
    
    /**
     * 获取所有课程公告
     *
     * @return 课程公告列表
     */
    @GetMapping
    public Result<List<CourseAnnouncement>> getAllAnnouncements() {
        return courseAnnouncementService.getAllAnnouncements();
    }
    
    /**
     * 根据ID获取课程公告
     *
     * @param announcementId 公告ID
     * @return 课程公告
     */
    @GetMapping("/{announcementId}")
    public Result<CourseAnnouncement> getAnnouncementById(@PathVariable Long announcementId) {
        return courseAnnouncementService.getAnnouncementById(announcementId);
    }
    
    /**
     * 获取课程公告列表（按课程和班级）
     *
     * @param courseId 课程ID
     * @param classId 班级ID
     * @return 课程公告列表
     */
    @GetMapping("/list")
    public Result<List<CourseAnnouncement>> getAnnouncementsByCourseAndClass(
            @RequestParam String courseId, 
            @RequestParam Long classId) {
        return courseAnnouncementService.getAnnouncementsByCourseAndClass(courseId, classId);
    }
    
    /**
     * 获取教师发布的课程公告
     *
     * @param teacherId 教师ID
     * @return 课程公告列表
     */
    @GetMapping("/teacher/{teacherId}")
    public Result<List<CourseAnnouncement>> getAnnouncementsByTeacherId(@PathVariable String teacherId) {
        return courseAnnouncementService.getAnnouncementsByTeacherId(teacherId);
    }
    
    /**
     * 添加课程公告
     *
     * @param announcement 课程公告信息
     * @return 添加结果
     */
    @PostMapping
    public Result<?> addAnnouncement(@RequestBody CourseAnnouncement announcement) {
        return courseAnnouncementService.addAnnouncement(announcement);
    }
    
    /**
     * 更新课程公告
     *
     * @param announcementId 公告ID
     * @param announcement 课程公告信息
     * @return 更新结果
     */
    @PutMapping("/{announcementId}")
    public Result<?> updateAnnouncement(
            @PathVariable Long announcementId, 
            @RequestBody CourseAnnouncement announcement) {
        return courseAnnouncementService.updateAnnouncement(announcementId, announcement);
    }
    
    /**
     * 删除课程公告
     *
     * @param announcementId 公告ID
     * @return 删除结果
     */
    @DeleteMapping("/{announcementId}")
    public Result<?> deleteAnnouncement(@PathVariable Long announcementId) {
        return courseAnnouncementService.deleteAnnouncement(announcementId);
    }
} 